<?php

namespace app\admin\controller;

use app\admin\model\TieBa;
use app\common\controller\Send;
use app\common\enums\StatusEnum;
use app\admin\model\TieBaCollect AS CollectModel;
use app\admin\model\TieBaType;

class TieBaCollect extends Base
{
    use Send;

    /**
     * 列表
     * @return \think\response\View
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $search = input('');
        $oauthId = isset($search['oauth_id']) ? $search['oauth_id'] : 0;
        $typeId = isset($search['type_id']) ? $search['type_id'] : -1;
        $checkStatus = isset($search['check_status']) ? $search['check_status'] : -1;
        $type = isset($search['type']) ? $search['type'] : CollectModel::TYPE_COLLECT;
        $search = [
            'type' => $type,
            'oauth_id' => $oauthId,
            'type_id' => $typeId,
            'check_status' => $checkStatus
        ];
        $where = [];
        if ($search['type']) {
            $where[] = ['ot.type', '=', $search['type']];
        }
        if ($search['oauth_id'] > 0) {
            $where[] = ['ot.oauth_id', '=', $search['oauth_id']];
        }
        if ($search['type_id'] != null && $search['type_id'] != -1) {
            $where[] = ['t.type_id', '=', $search['type_id']];
        }

        if ($search['check_status'] != null && $search['check_status'] != -1) {
            $where[] = ['t.check_status', '=', $search['check_status']];
        }

        $model = CollectModel::getList($where);
        return view('index', [
            'detailType' => 3,
            'model' => $model['model'],
            'count' => $model['count'],
            'search' => $search,
            'status' => StatusEnum::$listExplain,
            'type' => TieBaType::getColumn(),
            'checkStatus' => TieBa::attributes('check_status'),
            'cancelUrl' => url('index', ['oauth_id' => $search['oauth_id']])
        ]);
    }
}
